layui.config({
    base: "/js/modules/"
}).extend({
    "listView": "listView"
});
layui.use(['form', 'listView', 'laydate', 'jquery', 'table'], function () {
    let layDate = layui.laydate,
        form = layui.form,
        table = layui.table,
        layer = layui.layer,
        $ = layui.$;

    layDate.render(
        {
            elem: "#beginTime", trigger: 'click',
            type: 'datetime'
        }
    );
    layDate.render(
        {
            elem: "#endTime", trigger: 'click',
            type: 'datetime'
        }
    );

    layui.listView.tableInit({
        id: 'user',
        url: 'page',
        page: true,
        cols: [
            {field: 'number', title: '序号', fixed: 'true', type: 'numbers'},
            {field: 'realName', title: '姓名'},
            {field: 'loginName', title: '登录名'},
            {field: 'mobile', title: '手机号'},
            {
                field: 'locked', title: '用户状态', templet: function (d) {
                    return d.locked ? "锁定" : "正常";
                }
            },
            {field: 'createTime', title: '创建时间'},
            {field: 'lastLoginTime', title: '最后登陆时间'},
            {fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
        ]
    });

    $('#add').on('click', function () {
        layer.open({
            title: '新增用户',
            type: 2,
            area: ['800px', '350px'],
            fixed: false, //不固定
            maxmin: true,
            content: 'toAddUser'
        });
    });

    //操作
    table.on('tool(user)', function(obj){
        var data = obj.data;
        if(obj.event === 'edit'){
            // layer.alert('编辑行：<br>'+ JSON.stringify(data))
            layer.open({
                title: '编辑用户',
                type: 2,
                area: ['800px', '350px'],
                fixed: false, //不固定
                maxmin: true,
                content: 'queryUser?id='+data.id
            });
        }
    });

});

